<template>
  <div class="attendance-group-setting">
    <div class="header">
      <div class="left">
        <el-button type="primary" @click="handleAdd">+ 新建</el-button>
        <el-button @click="handleBatchSetting">批量设置</el-button>
      </div>
      <div class="right">
        <el-input
          v-model="searchQuery"
          placeholder="搜索考勤组名称、负责人、人员"
          prefix-icon="el-icon-search"
          clearable
          @clear="handleSearch"
          @input="handleSearch"
        />
        <el-button class="filter-button" @click="handleFilter">筛选</el-button>
      </div>
    </div>

    <el-table
      :data="tableData"
      border
      style="width: 100%"
      v-loading="loading"
    >
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        prop="name"
        label="考勤组名称"
        min-width="150">
      </el-table-column>
      <el-table-column
        prop="type"
        label="类型"
        width="120">
      </el-table-column>
      <el-table-column
        prop="attendanceTime"
        label="考勤时间"
        min-width="180">
      </el-table-column>
      <el-table-column
        prop="memberCount"
        label="人数"
        width="80"
        align="center">
      </el-table-column>
      <el-table-column
        prop="manager"
        label="主负责人"
        width="120">
      </el-table-column>
      <el-table-column
        label="操作"
        width="120"
        fixed="right">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AttendanceGroupSetting',
  data() {
    return {
      searchQuery: '',
      loading: false,
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: [
        {
          name: '固定班制',
          type: '固定班制',
          attendanceTime: '09:00 ~ 18:00',
          memberCount: 6,
          manager: '赵伟'
        }
      ]
    }
  },
  methods: {
    handleAdd() {
      // TODO: 实现新建考勤组功能
      this.$message.info('新建考勤组功能待实现')
    },
    handleBatchSetting() {
      // TODO: 实现批量设置功能
      this.$message.info('批量设置功能待实现')
    },
    handleSearch() {
      // TODO: 实现搜索功能
      console.log('搜索关键词:', this.searchQuery)
    },
    handleFilter() {
      // TODO: 实现筛选功能
      this.$message.info('筛选功能待实现')
    },
    handleDelete(row) {
      this.$confirm('确认删除该考勤组吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // TODO: 实现删除功能
        this.$message.success('删除成功')
      }).catch(() => {})
    },
    handleSizeChange(val) {
      this.pageSize = val
      // TODO: 重新加载数据
    },
    handleCurrentChange(val) {
      this.currentPage = val
      // TODO: 重新加载数据
    }
  }
}
</script>

<style scoped>
.attendance-group-setting {
  padding: 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.left {
  display: flex;
  gap: 10px;
}

.right {
  display: flex;
  gap: 10px;
  align-items: center;
}

.right .el-input {
  width: 300px;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>